Attribute VB_Name = "modIniFile"
Option Explicit

Public Const HIGHSCORE_FILE = "highscore.dat"

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Sub ReadScore()

    Dim i As Integer
    Dim AppPath As String

    AppPath = IIf(Len(App.Path) = 3, App.Path, App.Path & "\")

    For i = 0 To 9
        frmHighScore.lblNames(i) = ReadString("name", CStr(i + 1), AppPath & HIGHSCORE_FILE)
        frmHighScore.lblScores(i) = ReadString("score", CStr(i + 1), AppPath & HIGHSCORE_FILE)
    Next

End Sub

Public Function ReadString(Sector As String, Keyword As String, IniFileName As String) As String

    Dim tmp As String * 255

    Call GetPrivateProfileString(Sector, Keyword, "", tmp, 255, IniFileName)
    ReadString = TrimNullChar(tmp)

End Function

Public Function TrimNullChar(str As String) As String

    Dim ZeroPos As Integer

    ZeroPos = InStr(1, str, vbNullChar)
    If ZeroPos > 0 Then
        TrimNullChar = Left(str, ZeroPos - 1)
    Else
        TrimNullChar = str
    End If

End Function

